//
//  PKAccountBalanceController.swift
//  Panku
//
//  Created by mac on 2017/2/14.
//  Copyright © 2017年 Monster. All rights reserved.
//

import UIKit
import SnapKit
import YYKit

class PKAccountBalanceController: PKBaseViewController {
    //MARK: - properties
    //UI
    lazy var backgroundView = UIImageView()
    lazy var containerView = PKBaseView()
    
    lazy var balanceLabel = UILabel()
    lazy var balanceDescLabel = UILabel()
    lazy var chargeView0 = PKAccountBalanceChargeView()
    lazy var chargeView1 = PKAccountBalanceChargeView()
    lazy var chargeView2 = PKAccountBalanceChargeView()
    
    //MARK: - life circle
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    
    //MARK: - UI
    override func setupRootView() {
        view.backgroundColor = UIColor.white
    }
    
    override func setupSubViews() {
        view.addSubview(backgroundView)
        view.addSubview(containerView)
        
        containerView.addSubview(balanceLabel)
        containerView.addSubview(balanceDescLabel)
        
        containerView.addSubview(chargeView0)
        containerView.addSubview(chargeView1)
        containerView.addSubview(chargeView2)
        
        backgroundView.snp.makeConstraints { (make) in
            make.edges.equalTo(view)
        }
        
        containerView.backgroundColor = UIColor.white
        containerView.layer.cornerRadius = 4
        containerView.layer.masksToBounds = true

        balanceLabel.textColor = UIColor.darkGray
        balanceLabel.text = "0"
        
        balanceDescLabel.textColor = UIColor.darkGray
        balanceDescLabel.text = "账户余额"
        
        
        
    }
    
    override func setupSubViewsConstraints() {
        containerView.snp.makeConstraints { (make) in
            make.height.equalTo(400*D_FACTOR_Y)
            make.width.equalTo(320*D_FACTOR_X)
            make.center.equalTo(view.snp.center)
        }
        
        balanceLabel.font = UIFont.systemFont(ofSize: 20)
        balanceLabel.textColor = UIColor.darkGray
        balanceLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(containerView.snp.centerX)
            make.top.equalTo(containerView.snp.top).offset(38)
            
        }
        
        balanceDescLabel.font = UIFont.systemFont(ofSize: 20)
        balanceDescLabel.textColor = UIColor.darkGray
        balanceDescLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(containerView.snp.centerX)
            make.top.equalTo(containerView.snp.top).offset(80)
        }
        
        chargeView0.snp.makeConstraints { (make) in
            make.left.equalTo(containerView.snp.left)
            make.right.equalTo(containerView.snp.right)
            make.height.equalTo(44)
            make.top.equalTo(balanceDescLabel.snp.bottom).offset(100)
        }
        
        chargeView1.snp.makeConstraints { (make) in
            make.left.equalTo(containerView.snp.left)
            make.right.equalTo(containerView.snp.right)
            make.height.equalTo(44)
            make.top.equalTo(chargeView0.snp.bottom).offset(20)
        }
        
        chargeView2.snp.makeConstraints { (make) in
            make.left.equalTo(containerView.snp.left)
            make.right.equalTo(containerView.snp.right)
            make.height.equalTo(44)
            make.top.equalTo(chargeView1.snp.bottom).offset(20)
        }
    }
    
    override func setupNavigationBar() {
        self.title = "账户"
    }
    
    override func bindViewModel() {
        
    }


}

class PKAccountBalanceChargeView: PKBaseView {
    
    //MARK: - properties
    //UI
    lazy var coinButton = PKBaseButton.createButton()
    lazy var RMBButton = PKBaseButton.createButton()
    
    override func setupView() {
        self.addSubview(coinButton)
        self.addSubview(RMBButton)
        
        coinButton.setTitleColor(UIColor.darkGray, for: .normal)
        coinButton.setTitle("42", for: .normal)
        coinButton.setImage(R.image.mine_coin(), for: .normal)
        coinButton.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.snp.centerY)
            make.left.equalTo(self.snp.left).offset(18)
        }
        
        RMBButton.setTitleColor(UIColor.darkGray, for: .normal)
        RMBButton.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.snp.centerY)
            make.width.equalTo(100)
            make.height.equalTo(44)
            make.right.equalTo(self.snp.right).offset(-17)
        }
        
        RMBButton.setTitle("$120", for: .normal)
        RMBButton.layer.cornerRadius = 22
        RMBButton.layer.masksToBounds = true
        RMBButton.addBlock(for: .touchUpInside) { (_) in
            //TODO:充值操作
        }
        
        RMBButton.layer.borderColor = UIColor.darkGray.cgColor
        RMBButton.layer.borderWidth = 1
        RMBButton.backgroundColor = UIColor.white
        
        
    }
}
